/*
 * @Author: wuzhouhai wzh200x@126.com
 * @Date: 2024-08-01 17:57:54
 * @LastEditors: wuzhouhai wzh200x@126.com
 * @LastEditTime: 2024-08-02 16:50:00
 * @FilePath: \dwys_web\assets\script\ui\ShopIn.ts
 * @Description: 
 */
import { _decorator, Component, Node } from 'cc';
import { CCComp } from '../../../extensions/oops-plugin-framework/assets/module/common/CCComp';
import * as proto from "../phoenix/protoc/ts/proto_app.js";
import { Prefab } from 'cc';
import { instantiate } from 'cc';
import { ShopPmt } from './shopPmt/ShopPmt';
import { oops } from '../../../extensions/oops-plugin-framework/assets/core/Oops';
import { GameEvent } from '../common/event/GameEvent';
const { ccclass, property } = _decorator;

@ccclass('ShopIn')
export class ShopIn extends CCComp {

    @property(Prefab)
    pmtPrefab:Prefab|undefined = undefined;

    reset(): void {
        throw new Error('Method not implemented.');
    }

    start() {
        oops.message.on(GameEvent.ClearRoomPmtInfo, this.OnClearRoomPmtInfo, this);
        oops.message.on(GameEvent.AddShopPmt, this.OnAddRoomPmt, this);
    }

    protected onDestroy(): void {
        oops.message.off(GameEvent.ClearRoomPmtInfo, this.OnClearRoomPmtInfo, this);
        oops.message.off(GameEvent.AddShopPmt, this.OnAddRoomPmt, this);
    }

    update(deltaTime: number) {
        
    }

    OnClearRoomPmtInfo(){
        this.node.removeAllChildren();
    }

    OnAddRoomPmt(event:string, roomPmtInfo:proto.Iroom_pmt_info){
        let pmtItem = instantiate(this.pmtPrefab!);
        this.node.addChild(pmtItem);
        pmtItem.getComponent(ShopPmt)!.InitPmt(roomPmtInfo!);
    }
}


